package com.api.server.controller;


import com.api.server.pojo.*;
import com.api.server.service.IVenueService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shi
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/venue")
public class VenueController {


    @Autowired
    private IVenueService venueService;

    //根据场馆id查询场馆信息
    @ApiOperation(value = "根据场馆id查询场馆信息")
    @PostMapping("/message")
    public RespBean message(String venuenumber){
        Venue venue = venueService.message(venuenumber);
        return Result.success("获取场馆信息成功！",venue);
    }


    //增加场馆
    @ApiOperation(value = "增加场馆")
    @PostMapping
    public Result add(@RequestBody Venue venue){
        if (venueService.message(venue.getVenuenumber())!=null){
            return Result.fail("该场馆编号已经被使用！");
        }
        venueService.add(venue);
        return Result.success(201,"场馆创建成功",venue);
    }


    //根据id删除场馆
    @ApiOperation(value = "删除场馆")
    @DeleteMapping("/{id}")
    public RespBean delete(@PathVariable("id") String id){
        Venue venue = venueService.getById(id);
        if (venue.getVenuenumber()==null){
            return Result.fail("不存在该场馆！");
        }
        venueService.delete(id);
        return RespBean.success("删除场馆成功！");
    }


    //根据管理单位查询场馆
    @ApiOperation(value = "根据管理单位查询场馆")
    @GetMapping("/{id}")
    public RespBean equByCdId(@PathVariable("id") String id){
        List<Venue> venues = venueService.equByCdId(id);
        return RespBean.success("查询成功！",venues);
    }


    //根据id编辑场馆信息
    @ApiOperation(value = "根据id编辑场馆信息")
    @PutMapping("/updata")
    public RespBean updataById(@RequestBody Venue venue){
        int row = venueService.updataById(venue);
        return RespBean.success("修改成功！",row);
    }


    //根据场馆状态查看场馆列表
    @ApiOperation(value = "根据场馆状态查看场馆列表")
    @GetMapping("/venues")
    public RespBean venues(UserListPage userListPage){
        Map<String,Object> map = venueService.page(userListPage);
        return Result.success("获取普通用户列表成功！",map);
    }

}
